home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / sun / NET / WWW / URLConnection.class (.txt) < prev   
Encoding:
Java Class File  |  1997-04-14  |  2.1 KB  |  120 lines

  1. package sun.net.www;
  2.  
  3. import java.io.IOException;
  4. import java.net.URL;
  5.  
  6. public abstract class URLConnection extends java.net.URLConnection {
  7.    private String contentType;
  8.    private int contentLength = -1;
  9.    private MessageHeader properties;
  10.  
  11.    public URLConnection(URL var1) {
  12.       super(var1);
  13.    }
  14.  
  15.    public MessageHeader getProperties() {
  16.       return this.properties;
  17.    }
  18.  
  19.    public void setProperties(MessageHeader var1) {
  20.       this.properties = var1;
  21.    }
  22.  
  23.    public String getHeaderField(String var1) {
  24.       try {
  25.          ((java.net.URLConnection)this).getInputStream();
  26.       } catch (Exception var3) {
  27.          return null;
  28.       }
  29.  
  30.       MessageHeader var2 = this.properties;
  31.       return var2 == null ? null : var2.findValue(var1);
  32.    }
  33.  
  34.    public String GetHeaderFieldKey(int var1) {
  35.       try {
  36.          ((java.net.URLConnection)this).getInputStream();
  37.       } catch (Exception var3) {
  38.          return null;
  39.       }
  40.  
  41.       MessageHeader var2 = this.properties;
  42.       return var2 == null ? null : var2.getKey(var1);
  43.    }
  44.  
  45.    public String GetHeaderField(int var1) {
  46.       try {
  47.          ((java.net.URLConnection)this).getInputStream();
  48.       } catch (Exception var3) {
  49.          return null;
  50.       }
  51.  
  52.       MessageHeader var2 = this.properties;
  53.       return var2 == null ? null : var2.getValue(var1);
  54.    }
  55.  
  56.    public String getContentType() {
  57.       if (this.contentType == null) {
  58.          this.contentType = this.getHeaderField("content-type");
  59.       }
  60.  
  61.       if (this.contentType == null) {
  62.          String var1 = null;
  63.  
  64.          try {
  65.             var1 = java.net.URLConnection.guessContentTypeFromStream(((java.net.URLConnection)this).getInputStream());
  66.          } catch (IOException var3) {
  67.          }
  68.  
  69.          String var2 = this.properties.findValue("content-encoding");
  70.          if (var1 == null) {
  71.             var1 = this.properties.findValue("content-type");
  72.             if (var1 == null) {
  73.                if (super.url.getFile().endsWith("/")) {
  74.                   var1 = "text/html";
  75.                } else {
  76.                   var1 = java.net.URLConnection.guessContentTypeFromName(super.url.getFile());
  77.                }
  78.             }
  79.          }
  80.  
  81.          if (var1 == null || var2 != null && !var2.equalsIgnoreCase("7bit") && !var2.equalsIgnoreCase("8bit") && !var2.equalsIgnoreCase("binary")) {
  82.             var1 = "content/unknown";
  83.          }
  84.  
  85.          this.contentType = var1;
  86.       }
  87.  
  88.       return this.contentType;
  89.    }
  90.  
  91.    public void setContentType(String var1) {
  92.       this.contentType = var1;
  93.    }
  94.  
  95.    public int getContentLength() {
  96.       int var1 = this.contentLength;
  97.       if (var1 < 0) {
  98.          try {
  99.             var1 = Integer.parseInt(this.properties.findValue("content-length"));
  100.             this.contentLength = var1;
  101.          } catch (Exception var2) {
  102.          }
  103.       }
  104.  
  105.       return var1;
  106.    }
  107.  
  108.    protected void setContentLength(int var1) {
  109.       this.contentLength = var1;
  110.    }
  111.  
  112.    public boolean canCache() {
  113.       return super.url.getFile().indexOf(63) < 0;
  114.    }
  115.  
  116.    public void close() {
  117.       super.url = null;
  118.    }
  119. }
  120.